import React from 'react';
import {
	Button,
	Group,
	TextareaField,
	Toast,
	SelectField,
	SwitchField,
	Dialog,
} from 'saltui';
const {
	Count
} = TextareaField;
import PageController from 'pages/home';
import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap
} from '../../../app/variables';
import DB from '../../../app/db';

import Util from 'components/common/util';

export default class PageHome extends React.Component {

	constructor(props) { 
		super(props);		
		let id = props.params.id;
		let route = props.params.route;
		this.state = {
			form: {
				id: id,
				route: route,
				rejction: '',
			}
		}

			dd.biz.navigation.setTitle({
      		title: '意见反馈',
		    onSuccess: function (result) {
		    },
     		 onFail: function () {
      		}
    		});
		

	}

	componentWillMount() {

	}

	componentDidMount() {
		
	}

		/**
	 * 多行文件值改变事件， 支持字符长度判断
	 * @param  {[type]} field    [description]
	 * @param  {[type]} size     [description]
	 * @param  {[type]} newValue [description]
	 * @return {[type]}          [description]
	 */
	handleTextAreaChange(field, size, newValue) {
		if (newValue.length <= size) {
			let form = this.state.form;
			form[field] = newValue;
			this.setState({
				form
			});
		}
	}

		/**
	 * 取消提交表单
	 * @return {[type]}
	 */
	handleSave() {
		this.saveSubmit("0");
	}

		/**
	 * 表单提交
	 * @return {[type]}
	 */
	saveSubmit(){
		this.setState({
			buttonAble:true
		},()=>{
			this.handleSubmit();
		})
	}

	handleSubmit() {
		if(this.state.form.rejction==undefined||this.state.form.rejction.trim()=="" ){
			Toast.show({
				type: 'error',
				content: '驳回理由不能为空',
				onHide: function () {}
			});
			this.setState({
				buttonAble:false
			})
		return false;
		}
		if(isEmojiCharacter(this.state.form.rejction)){
			Toast.show({
			type: 'error',
			content: '驳回理由不能输入表情',
			onHide: function () {}
	 });
		this.setState({
				buttonAble:false
			})
		return false;
		}

		this.returnPostInfo(this.state.form.id,this.state.form.rejction,this.state.form.route);
	}

	returnPostInfo(id,rejction,route){
		DB.ForumModuleAPI.returnInfo({
			id:id,
			rejction:rejction
		}).then((content) =>{
			Dialog.alert({
				title: '提交',
				content: '审核成功',
			});
			if(route=="myCheckList"){
				history.go(-1);
			}else{
				history.go(-1);
				//backPage();
				//history.go(-2);
			}
		}).catch((error) => {
			Toast.show({
				type: 'error',
				content: '提交出错'
			});
		})
	}

	render() {
		let t = this; 
		return (
			<div className="page-add">
				<Group>
	        <Group.List >
	          <TextareaField
	            required
	            label="驳回理由"
	            minRows={8} maxRows={11}
							placeholder="1-200个字符"
							value={this.state.form.rejction}
							onChange={this.handleTextAreaChange.bind(this, 'rejction', 200)}
	             >
	            <Count total={200} length={this.state.form.rejction.length} />
	          </TextareaField>
	        </Group.List>
				</Group>
				<div>
					<Button.Group className="page-add">					
					  <Button type="primary" display="inline"
					    onClick={this.saveSubmit.bind(this)}>提交</Button>	  
					</Button.Group>
				</div>		
			</div>
		);
	}
}